<cfcomponent output="false" mixin="controller" hint="hint">

	<cffunction name="init">
		<cfset this.version = "1.0">
		<cfreturn this>
	</cffunction>

	<cffunction name="gravatarTag" access="public" returnType="string" hint="Creates a simple view helper to embed gravatar in your ColdFusion on Wheels application.">
		<cfargument name="email" type="string" required="true">
		<cfargument name="size" type="numeric" required="false" default="80">
		<cfargument name="rating" type="string" required="false" default="g">
		<cfargument name="default" type="string" required="false" default="">
		
		<cfset var loc = {}>		
		<cfset loc.gravatarArgs = arguments>

		<!--- Build Gravatar Url --->
		<cfset loc.email = Trim(LCase(arguments.email))>
		<cfset loc.gravatarId = LCase(Hash(loc.email, "MD5"))>
		<cfset loc.gravatarArgs.source = "http://www.gravatar.com/avatar/" & loc.gravatarId & ".jpg?size=" & arguments.size & "&rating=" & arguments.rating & "&default=" & UrlEncodedFormat(arguments.default)>
		
		<!--- Destroy unneeded args --->
		<cfset StructDelete(loc.gravatarArgs, "email")>
		<cfset StructDelete(loc.gravatarArgs, "size")>
		<cfset StructDelete(loc.gravatarArgs, "rating")>
		<cfset StructDelete(loc.gravatarArgs, "default")>

		<cfreturn imageTag(argumentCollection=loc.gravatarArgs)>				
	</cffunction>

</cfcomponent>